package com.sunseen.intelligencebus.riding

import android.os.Bundle
import android.util.Log
import android.widget.RadioGroup
import android.widget.TextView
import androidx.databinding.ViewDataBinding
import com.sunseen.intelligencebus.R
import com.sunseen.intelligencebus.base.AbsBindingFragment
import com.sunseen.intelligencebus.databinding.FragmentRidingBinding


class RidingFragment : AbsBindingFragment() {

    companion object {
        fun newInstance(): RidingFragment {
            return RidingFragment()
        }

        const val StationStr = "Station"

    }

    var stationChar = "A"

    lateinit var stationTv: TextView

    override fun setLayout(): Int {
        return R.layout.fragment_riding
    }


    override fun onBindView(viewDataBinding: ViewDataBinding, bundle: Bundle?) {


        val binding = viewDataBinding as FragmentRidingBinding
        stationTv = binding.goalStationTv
        binding.stationRadioGroup.setOnCheckedChangeListener(object : RadioGroup.OnCheckedChangeListener {
            override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
                when (checkedId) {
                    R.id.station_1_rb -> {
                        stationTv.text = getString(R.string.station_1)
                        stationChar = "A"
                    }
                    R.id.station_2_rb -> {
                        stationTv.text = getString(R.string.station_2)
                        stationChar = "B"
                    }
                    R.id.station_3_rb -> {
                        stationTv.text = getString(R.string.station_3)
                        stationChar = "C"
                    }
                    R.id.station_4_rb -> {
                        stationTv.text = getString(R.string.station_4)
                        stationChar = "D"
                    }
                    R.id.station_5_rb -> {
                        stationTv.text = getString(R.string.station_5)
                        stationChar = "E"
                    }
                    R.id.station_6_rb -> {
                        stationTv.text = getString(R.string.station_6)
                        stationChar = "F"
                    }
                }
                Log.e("test", "stationChar$stationChar")
            }
        })

        binding.confirmStationBtn.setOnClickListener {
            val codeFragment = QRCodeFragment()
            val charBundle = Bundle()
            charBundle.putString(StationStr, stationChar)
            codeFragment.arguments = charBundle
            getParentDelegate<AbsBindingFragment>().start(codeFragment)
        }
    }

}
